package com.eastcom.bm.dao.impl;

import java.util.ArrayList;
import java.util.List;

import com.eastcom.bm.atom.Atom_DatasetDefine;
import com.eastcom.bm.dao.AbstractDAO;
import com.eastcom.bm.dao.IDataSetDao;
import com.eastcom.common.db.JDBCTemplate;
import com.eastcom.common.db.ResultData;

public class DataSetDao extends AbstractDAO implements IDataSetDao {

	public List<Atom_DatasetDefine> getAllDataSetDefine() throws Exception {
		List<Atom_DatasetDefine> results=new ArrayList<Atom_DatasetDefine>();
		try{
			String sql="select id,name_cn,ne_type,BASE_INTEGER_VALUE,DEVIATION from qa_dataset_define";
			ResultData rd=JDBCTemplate.executeSQLQuery(sql, JDBCTemplate.PROPAGATION_NEVER, false, false);
			while(rd.next()){
				Atom_DatasetDefine dataSet=new Atom_DatasetDefine();
				dataSet.setId(rd.getString("ID"));
				dataSet.setCn_name(rd.getString("NAME_CN"));
				dataSet.setNeType(rd.getString("NE_TYPE"));
				dataSet.setBaseIntegerValue(rd.getDouble("BASE_INTEGER_VALUE"));
				dataSet.setDeviation(rd.getDouble("DEVIATION"));
				dataSet.setAttentionType(rd.getString("ATTENTION_TYPE"));
				results.add(dataSet);
			}

			return results;
		}
		catch(Exception e){
			throw e;
		}
	}

	public Atom_DatasetDefine findDatasetDefineById(String id) throws Exception {
		try{
			String sql="select id,name_cn,ne_type,BASE_INTEGER_VALUE,DEVIATION from qa_dataset_define where id='"+id+"'";
			ResultData rd=JDBCTemplate.executeSQLQuery(sql, JDBCTemplate.PROPAGATION_NEVER, false, false);
			
			while(rd.next()){
				Atom_DatasetDefine dataSet=new Atom_DatasetDefine();
				dataSet.setId(rd.getString("ID"));
				dataSet.setCn_name(rd.getString("NAME_CN"));
				dataSet.setNeType(rd.getString("NE_TYPE"));
				dataSet.setBaseIntegerValue(rd.getDouble("BASE_INTEGER_VALUE"));
				dataSet.setDeviation(rd.getDouble("DEVIATION"));
				dataSet.setAttentionType(rd.getString("ATTENTION_TYPE"));

                return dataSet;
			}
			
			return null;
		}
		catch(Exception e){
			throw e;
		}
	}

}
